package chapter_23.runnable;

/**
 * Created by Administrator
 * Created time 2018/8/9 17:32.
 * 实现 Runnable 接口
 */
public class Runner implements Runnable {
    // 编写执行线程代码
    @Override
    public void run() {
        for (int i = 1; i < 10; i++) {
            // 打印次数和线程的名字
            System.out.printf("第 %d次执行 - %s\n", i, Thread.currentThread().getName());

            try {
                // 随机生成休眠时间
                long sleepTime = (long) (1000 * Math.random());
                // 线程休眠
                Thread.sleep(sleepTime);
            } catch (InterruptedException e) {
            }
        }
        // 线程执行结束
        System.out.println("执行完成! " + Thread.currentThread().getName());
    }
}
